home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-02-05 | 14.5 KB | 487 lines | [TEXT/MPS ] |
- // Copyright © 1991 Apple Computer, Inc. All rights reserved.
-
- #ifndef __UCORE__
- #define __UCORE__
-
- #ifndef __MACAPP__
- #include <MacApp.h>
- #endif
-
- #ifndef __UDIALOG__
- #include <UDialog.h>
- #endif
-
- #ifndef __UBUSYCURSOR__
- #include <UBusyCursor.h>
- #endif
-
- #ifndef __UITERATOR__
- #include <UIterator.h>
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef __EPPC__
- #include <EPPC.h>
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif
-
- #ifndef __STRING__
- #include <String.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef __PPCTOOLBOX__
- #include <PPCToolbox.h>
- #endif
-
- #ifndef __AEOBJECTS__
- #include <AEObjects.h>
- #endif
-
- #ifndef __AEOBJECTPACKING__
- #include <AEPackObject.h>
- #endif
-
- class TCell; // forward declarations
- class TRecordCell;
-
- typedef pascal void (*DoToACellProc)(TCell *aCell, void *params);
- typedef pascal Boolean (*TestACellProc)(TCell *aCell, void *params);
- typedef pascal void (*DoToObject)(TObject *anObject, void *link);
- typedef pascal Boolean (*TestItem)(TObject *anObject, void *link);
-
- typedef TCell *CellPtr;
- typedef enum CellState
- {
- kBlack,
- kWhite,
- kEmpty,
- kNeighbor,
- kAvailable
- } CellState;
-
- typedef enum GameState
- {
- kWhiteTurn,
- kBlackTurn,
- kWhiteTurnPass,
- kBlackTurnPass,
- kGameOver
- } GameState;
-
- typedef enum TestState
- {
- kAnother,
- kSame,
- kNoHit,
- kHit
- } TestState;
-
- typedef enum Direction
- {
- kNorth,
- kNorthEast,
- kEast,
- kSouthEast,
- kSouth,
- kSouthWest,
- kWest,
- kNorthWest
- } Direction;
-
- typedef enum InvertFlag
- {
- kTest,
- kInvert
- } InvertFlag;
-
- typedef enum GameResult
- {
- kWin,
- kDraw,
- kLose,
- kClose
- } GameResult;
-
- typedef enum PlayerStatus
- {
- kFailed = -1,
- kNotReady,
- kReady
- } PlayerStatus;
-
- typedef enum
- {
- kBeginTransactionReturnID = 'BT',
- kNewElementReturnID = 'NE',
- kSetDataReturnID = 'SD',
- kEndTransactionReturnID = 'ET'
- } ReturnID;
-
- const OSType kFileType = 'TARO';
- const OSType kSignature = 'TARO';
- const OSType kServerSignature = 'Taro';
- const OSType kApplicationFType = 'APPL';
-
- const AEEventClass kTaroClass = 'TARO';
- const AEEventID kGameOverID = 'OVER';
- const AEKeyword keyGameResult = 'RSLT';
- const AEKeyword keyClientName = 'NAME';
-
- const DescType typeTObjectPtr = typeMagnitude;
-
- const AEEventClass kAECoreSuite = 'core';
- const DescType cTable = 'ctbl';
- const DescType cCell = 'ccel';
- const DescType typeCell = 'cell';
- const AEEventID kAENewElement = 'nobj';
- const AEEventID kAESetData = 'setd';
- const AEEventID kAEBeginTransaction = 'begi';
- const AEEventID kAEEndTransaction = 'endt';
- const AEEventID kAEAbout = 'abou';
- const AEKeyword keyAEObjectClass = 'kocl';
- const AEKeyword keyAEInsertHere = 'insh';
- const AEKeyword keyAEData = 'data';
- const AEKeyword keyAETheData = 'kdat';
- const AEKeyword keyAETheTransID = 'tran';
-
- const AEKeyword keyTaroColumnNumber = 'CNUM';
- const AEKeyword keyTaroRowNumber = 'RNUM';
- const AEKeyword keyTaroColor = 'COLR';
- const AEKeyword keyTaroUserName = 'NAME';
- const AEKeyword keyTaroTableSpecifier = 'TSPC';
-
- const OSErr errAEFail = -1732;
- const OSErr errAEUserCanceled = -1740;
-
- const short kPlayerString = 2000;
- const short kStatusMessage = 2001;
- const short kGameOverMessage = 2002;
-
- const CommandNumber cNewClient = cNew;
- const CommandNumber cNewServer = cNewClient + 1;
- const CommandNumber cNewElement = cNewServer + 1;
-
- class TPlayer;
- // ============================== Service Routines =================================
- char TranslateCellSize(char anItem);
- OSErr CheckPPC(void);
- void ShowModalDialog(short DialogID);
- void InstallNotification(void);
-
- class TCoreDocument;
- class TAppleEventPlayer;
- class TNewServerCommand;
- class TNewElementCommand;
- // ==========================================================================================
- class TCoreApplication: public TApplication {
- private:
- TList * fNewElementCommandList;
- public:
- virtual pascal void ITaroApplication(void);
- virtual pascal void InsertNewElementCommand(TNewElementCommand * aNewElementCommand);
- virtual pascal void RemoveNewElementCommand(void);
- virtual pascal TNewElementCommand * GetNewElementCommand(void);
-
- virtual pascal TDocument * FindDocumentFromName(Str255 & theName);
- virtual pascal TAppleEventPlayer * CreateServerPlayer(void);
- };
-
- // ==========================================================================================
- class TCoreDocument: public TDocument {
- private:
- char fHCellSize;
- char fVCellSize;
- TPlayer * fBlackPlayer;
- TPlayer * fWhitePlayer;
- GameState fTurn;
- public:
- virtual pascal void ICoreDocument(char aHCellSize, char aVCellSize,
- char aBlackPlayer, char aWhitePlayer);
- virtual pascal TPlayer * CreatePlayer(char PlayerType, CellState aColor);
- virtual pascal void DoMakeViews(Boolean forPrinting);
- virtual pascal void SetPlayerStatus(void);
- virtual pascal void GetCellSize(char & HCellSize, char & VCellSize);
- virtual pascal void GameOver(void);
- virtual pascal void GameClose(void);
- virtual pascal void Free(void);
- virtual pascal TPlayer * GetPlayer(GameState aState);
- virtual pascal void Close(void);
- virtual pascal GameState GetTurn(void);
- virtual pascal CellState GetTurnCellState(void);
- virtual pascal void SwitchTurn(Boolean Pass);
- virtual pascal TPlayer * GetTemporaryPlayer(void);
- virtual pascal TPlayer * GetAnotherPlayer(void);
- virtual pascal void PlayerMove(TRecordCell * aMouseMove);
- virtual pascal void SendTurn(void);
- virtual pascal void CreateTableSpecifier(AEDesc & aTableSpec);
- };
-
-
- // ==========================================================================================
- class TScene: public TObject {
- private:
- TList *fCellList;
- short fBlack, fWhite;
- short fAvailable;
- TCoreDocument *fCoreDocument;
- TList *fNeighborCellList;
- CellState fTurn;
- public:
- virtual pascal void IScene(TCoreDocument * aCoreDocument);
- virtual pascal TCoreDocument * ReturnCoreDocument(void);
- virtual pascal void AddCellLast(TCell *aCell);
- virtual pascal TCell * GetCell(char aColumn, char aRow);
- virtual pascal TCell * CreateCell(char aColumn, char aRow);
- virtual pascal CellState GetTurn(void);
- virtual pascal void SetTurn(CellState aTurn);
- virtual pascal void GameOver(void);
- virtual pascal void ChangeCount(CellState aColor, short aNumber);
- virtual pascal short GetCount(CellState aColor);
- virtual pascal void Free(void);
- virtual pascal void SetInitialState(void);
- virtual pascal void SearchAvailableCell(void);
- virtual pascal void AddAvailable(void);
- virtual pascal void ResetAvailable(void);
- virtual pascal void AddNeighborCellLast(TCell *aCell);
- virtual pascal short HasAvailableCell(void);
- virtual pascal short GetAvailableCell(void);
- virtual pascal TCell * SearchNeighborCellList(TRecordCell * theCoordinate);
- virtual pascal void DeleteNeighborCell(TCell *theCell);
- virtual pascal TList * GetNeighborCellList(void);
- };
-
-
- // ==========================================================================================
- class TCoordinate: public TObject {
- private:
- char fColumn, fRow;
- public:
- virtual pascal void ICoordinate(const char column, const char row);
- virtual pascal char GetColumn(void);
- virtual pascal char GetRow(void);
- virtual pascal Boolean IsEqual(TCoordinate *theCoordinate);
- };
-
-
- // ==========================================================================================
- class TRecordCell: public TCoordinate {
- private:
- CellState fState;
- public:
- virtual pascal void IRecordCell(const char column, const char row, CellState aState);
- virtual pascal CellState GetState(void);
- virtual pascal GameState GetGameState(void);
- virtual pascal void SetState(CellState aState);
- virtual pascal Boolean IsEmpty(void);
- virtual pascal Boolean IsNeighbor(void);
- virtual pascal void SetNeighbor(void);
- virtual pascal Boolean IsAvailable(void);
- virtual pascal void SetAvailable(void);
- virtual pascal TRecordCell * CloneRecordCell(void);
- };
-
-
- // ==========================================================================================
- class TCell: public TRecordCell {
- private:
- TScene * fScene;
- public:
- virtual pascal void ICell(TScene *aScene, const char column, const char row);
- virtual pascal TScene * GetScene(void);
- virtual pascal void ChangeState(void);
- virtual pascal void PutPiece(void);
- virtual pascal void SetNeighbor(void);
- virtual pascal TCell * GetNeighborCell(Direction aDirection);
- virtual pascal void SetNeighborCell(void);
- virtual pascal TestState ScanOneDriection( Direction aDirection,
- TestState aTestState,
- TCell * aCell);
- virtual pascal void GetCornerCoordinate(char & h, char & v,
- char & aHCellSize, char & aVCellSize);
- virtual pascal void ScanAllDriection(void);
- virtual pascal void HitCell(TCell * aTurnCell);
- };
-
-
- // ==========================================================================================
- class TPlayer: public TObject {
- private:
- TCoreDocument * fCoreDocument;
- Boolean fPermission;
- PlayerStatus fStatus;
- public:
- virtual pascal void Initialize(void);
- virtual pascal void IPlayer(TCoreDocument * aCoreDocument);
- virtual pascal void MyTurn(void);
- virtual pascal void MyMove(TRecordCell * aCellRecord);
- virtual pascal void YourMove(TRecordCell * aCellRecord);
- virtual pascal pascal TCoreDocument * GetCoreDocument(void);
- virtual pascal void SetCoreDocument(TCoreDocument * aCoreDocument);
- virtual pascal Boolean GetPermission(void);
- virtual pascal PlayerStatus GetStatus(void);
- virtual pascal void SetStatus(PlayerStatus aStatus);
- virtual pascal void GetName(Str255 & aString);
- virtual pascal void MouseMove(TRecordCell * aMouseMove);
- virtual pascal void GameOver(GameResult aResult);
- };
-
-
- class TTarget;
- // ==========================================================================================
- class TAppleEventPlayer: public TPlayer {
- private:
- unsigned long fTargetTransactionID;
- CellState fMyColor;
- TTarget * fTarget;
- TRecordCell * fMove;
- Boolean fWait;
- AEDesc fObjSpec;
- public:
- virtual pascal void Initialize(void);
- virtual pascal void IAppleEventPlayer(TCoreDocument * aCoreDocument, CellState aColor);
- virtual pascal unsigned long GetTargetTransactionID(void);
- virtual pascal void SetTargetTransactionID(unsigned long aTargetTransactionID);
- virtual pascal void SetTargetTableSpecifier(AEDesc & TableSpec);
- virtual pascal CellState GetMyColor(void);
- virtual pascal void SetMyColor(CellState aColor);
- virtual pascal void GameOver(GameResult aResult);
- virtual pascal void MyTurn(void);
- virtual pascal void MyMove(TRecordCell * aCellRecord);
- virtual pascal void YourMove(TRecordCell * aCellRecord);
- virtual pascal TTarget * ReturnTarget(void);
- virtual pascal void SetTarget(TTarget * aTartget);
- virtual pascal void EndTransaction(void);
- virtual pascal void CreateTargetCellSpecifier(TRecordCell * aCell, AEDesc & dCellSpec);
- virtual pascal void Free(void);
- };
-
- // ==========================================================================================
- class TTarget: public TObject {
- private:
- AEAddressDesc fTargetAddress;
- public:
- virtual pascal void ITarget(AEAddressDesc & TargetID);
- virtual pascal void CreateDesc(DescType typeCode, Ptr dataPtr, Size dataSize);
- virtual pascal void Free(void);
- virtual pascal void SendSetData(TRecordCell * aMove, unsigned long aTransactionID, AEDesc & cellSpec);
- virtual pascal void SendEndTransaction(GameResult aResult, unsigned long theServer, TPlayer * theClient);
- virtual pascal TAppleEvent * CreateAppleEvent(AEEventClass theAEEventClass, AEEventID theAEEventID,
- short returnID, long transactionID);
- virtual pascal void GetName(Str255 & userName);
- };
-
- // ==========================================================================================
- class TServerTarget: public TTarget {
- private:
- Str255 fUserName;
- public:
- virtual pascal void IServerTarget(AEAddressDesc & TargetID);
- virtual pascal void SetName(const Str255 & userName);
- virtual pascal void GetName(Str255 & userName);
- };
-
- // ==========================================================================================
- class TNoChangesCommand: public TCommand {
- private:
- public:
- virtual pascal void INoChangesCommand(void);
- };
-
- // ==========================================================================================
- class TCloseDocumentCommand: public TNoChangesCommand {
- private:
- TCoreDocument * fDocument;
- public:
- virtual pascal void ICloseDocumentCommand(TCoreDocument * aDocument);
- virtual pascal void DoIt(void);
- };
-
- // ==========================================================================================
- class TStartDocumentCommand: public TNoChangesCommand {
- private:
- TCoreDocument * fDocument;
- public:
- virtual pascal void IStartDocumentCommand(TCoreDocument * aDocument);
- virtual pascal void DoIt(void);
- };
-
- // ==========================================================================================
- class TNewElementCommand: public TServerCommand {
- private:
- char fServerHCellSize;
- char fServerVCellSize;
- char fServerColor;
- TAppleEventPlayer * fNewServer;
- public:
- virtual pascal void INewElementCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
- virtual pascal void DoIt(void);
- virtual pascal void HandleReply(AEDesc & aTargetObject);
- virtual pascal void GetServerParameter(char & aHCellSize, char & aVCellSize, char & aColor,
- TAppleEventPlayer * (& aNewServer));
- };
-
- // ==========================================================================================
- class TBeginTransactionCommand: public TServerCommand {
- private:
- public:
- virtual pascal void IBeginTransactionCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
- virtual pascal void DoIt(void);
- };
-
- // ==========================================================================================
- class TEndTransactionCommand: public TServerCommand {
- private:
- public:
- virtual pascal void IEndTransactionCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
- };
-
- // ==========================================================================================
- class TSetDataCommand: public TServerCommand {
- private:
- public:
- virtual pascal void ISetDataCommand(AppleEvent & theAppleEvent, AppleEvent & Reply);
- virtual pascal void DoIt(void);
- };
-
- // ==========================================================================================
- class TMoveCommand: public TCommand {
- private:
- TPlayer * fPlayer;
- TRecordCell * fMove;
- public:
- virtual pascal void IMoveCommand(TPlayer * aPlayer, TRecordCell * aMove);
- virtual pascal void DoIt(void);
- };
-
- // ==========================================================================================
- class TSendTurnCommand: public TCommand {
- private:
- public:
- virtual pascal void ISendTurnCommand(TCoreDocument * aCoreDocument);
- virtual pascal void DoIt(void);
- };
-
- #endif
-